//
//  JJPhotoManager.swift
//  JJAlbumBrowser
//
//  Created by 吴梓杭 on 2025/10/10.
//

import UIKit
import Photos

//@objcMembers
public class JJPhotoManager: NSObject {
    
    /// 获取所有相册列表
    /// - Parameters:
    ///   - ascending: 是否倒序
    ///   - allowSelectImage: 是否获取图片
    ///   - allowSelectVideo: 视频获取视频
    ///   - completion: 返回相册列表
    @objc public class func getPhotoAlbumList(_ completion: ([JJAlbumListModel]) -> Void) {
        internal_getPhotoAlbumList(completion)
    }
    
    
    /// 获取压缩图片
    /// - Parameters:
    ///   - asset: 资源
    ///   - size: 显示大小
    ///   - progress: 进度
    ///   - completion: 图片回调
    /// - Returns: PHImageRequestID
    @discardableResult
    public class func fetchImage(for asset: PHAsset, size: CGSize, progress: ((CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable: Any]?) -> Void)? = nil, completion: @escaping (UIImage?, Bool) -> Void) -> PHImageRequestID {
        return internal_fetchImage(for: asset, size: size, resizeMode: .fast, progress: progress, completion: completion)
    }
    
    
    /// 获取原图
    /// - Parameters:
    ///   - asset: 资源
    ///   - progress: 进度
    ///   - completion: 图片回调
    /// - Returns: PHImageRequestID
    @discardableResult
    public class func fetchOriginalImage(for asset: PHAsset, progress: ((CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable: Any]?) -> Void)? = nil, completion: @escaping (UIImage?, Bool) -> Void) -> PHImageRequestID {
        return internal_fetchImage(for: asset, size: PHImageManagerMaximumSize, resizeMode: .fast, progress: progress, completion: completion)
    }
    
    
    /// 获取LivePhoto
    /// - Parameters:
    ///   - asset: 资源
    ///   - completion: 图片回调
    /// - Returns: PHImageRequestID
    @discardableResult
    public class func fetchLivePhoto(for asset: PHAsset, completion: @escaping (PHLivePhoto?, [AnyHashable: Any]?, Bool) -> Void) -> PHImageRequestID {
        return internal_fetchLivePhoto(for: asset, completion: completion)
    }
    
    /// 获取视频
    /// - Parameters:
    ///   - asset: 资源
    ///   - progress: 进度
    ///   - completion: 图片回调
    /// - Returns: PHImageRequestID
    @discardableResult
    public class func fetchVideo(for asset: PHAsset, progress: ((CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable: Any]?) -> Void)? = nil, completion: @escaping (AVPlayerItem?, [AnyHashable: Any]?, Bool) -> Void) -> PHImageRequestID {
        return internal_fetchVideo(for: asset, progress: progress, completion: completion)
    }
    
}
